home *** CD-ROM | disk | FTP | other *** search
- /**********************************************************************\
- * *
- * display.c -- graphics display functions, bitmaps, scrolling, etc. *
- * *
- \**********************************************************************/
-
- #include "defs.h"
- #include "birds.h"
- #include "tntmaps.h"
-
- /**********************************************************************\
- * *
- * do_bitmaps -- display some bitmaps on the screen *
- * *
- * the drawmap bitmaps are bigger than the drwimage bitmaps but you *
- * can have any transparent and visual colors you want *
- * *
- \**********************************************************************/
-
- do_bitmaps()
- {
- /* width, height, position and colors of TNT plunger bitmap */
-
- static int tnt_width[] = { 6, 3, 4, 4};
- static int tnt_height[] = {28, 25, 27, 17};
- static int tnt_color[] = { 0, 7, 8, 15};
- static int tnt_xoffset[] = { 0, 24, 16, 16};
- static int tnt_yoffset[] = { 0, -2, -1, -2};
- static char *tnt_bitmap[4] = {tnt0,tnt7,tnt8,tnt15};
-
- /* width, height, position and colors of "kablooy" explosion */
-
- static int kablooy_width[] = {13, 6};
- static int kablooy_height[] = {53, 8};
- static int kablooy_color[] = { 4, 15};
- static int kablooy_xoffset[] = { 0, 29};
- static int kablooy_yoffset[] = { 0,-24};
- static char *kablooy_bitmap[2] = {kablooy4,kablooy15};
-
- /* strings for info window */
-
- static char *string[] = {
- "Bitmaps",
- "Bitmaps can be clipped, flipped, mode-independent",
- "and mode-specific.",
- };
-
- register int i;
- int x,y;
- int ymin,ymax;
-
- /* clear lower part of screen */
-
- fg_mousevis(OFF);
- fg_restore(0,xlimit,menu_bottom,ylimit);
-
- /* display the info window */
-
- info_window(120,520,60,string,3);
-
- /* calculate where the TNT bitmap is going to go */
-
- ymin = 60;
- ymax = ymin + 4 * (PTSIZE+1);
-
- x = 520;
- y = ymax;
-
- /* put the TNT bitmap next to the info window */
-
- fg_mousevis(OFF);
- for (i = 0; i < 4; i++)
- {
- fg_move(x+tnt_xoffset[i],y+tnt_yoffset[i]);
- fg_setcolor(tnt_color[i]);
- fg_drawmap(tnt_bitmap[i],tnt_width[i],tnt_height[i]);
- }
-
- /* save info window to hidden page, to be replaced after the explosion */
-
- x = 440;
- y = ymax + 20;
- fg_save(400,520,ymin,y);
-
- /* take a rectangular bite out of the info window on the hidden page */
-
- fg_transfer(464,568,144,180,464,y-10,hidden,hidden);
-
- /* pause 1 second */
-
- fg_mousevis(ON);
- fg_waitfor(18);
-
- /* move the plunger down */
-
- fg_mousevis(OFF);
- fg_transfer(544,567,ymax-30,ymax-25,0,5,visual,hidden);
- fg_transfer(0,23,0,5,544,ymax-23,hidden,visual);
- fg_mousevis(ON);
- fg_waitfor(6);
-
- fg_mousevis(OFF);
- fg_transfer(0,23,0,5,544,ymax-21,hidden,visual);
- fg_mousevis(ON);
- fg_waitfor(6);
- fg_mousevis(OFF);
-
- /* display the explosion */
-
- for (i = 0; i < 2; i++)
- {
- fg_move(x+kablooy_xoffset[i],y+kablooy_yoffset[i]);
- fg_setcolor(kablooy_color[i]);
- fg_drawmap(kablooy_bitmap[i],kablooy_width[i],kablooy_height[i]);
- }
-
- /* blink the "kablooy" text 4 times */
-
- for (i = 0; i < 4; i++)
- {
- fg_waitfor(3);
- fg_move(x+kablooy_xoffset[1],y+kablooy_yoffset[1]);
- fg_setcolor(4);
- fg_drawmap(kablooy_bitmap[1],kablooy_width[1],kablooy_height[1]);
- fg_waitfor(3);
- fg_move(x+kablooy_xoffset[1],y+kablooy_yoffset[1]);
- fg_setcolor(15);
- fg_drawmap(kablooy_bitmap[1],kablooy_width[1],kablooy_height[1]);
- }
-
- /* wait a bit, then restore the info window with the corner missing */
-
- fg_waitfor(3);
- fg_restore(440,568,y-68,y);
-
- /* draw the torn edges of the info window using the tear bitmap */
-
- fg_setcolor(0);
- fg_move(461,ymax);
- fg_drawmap(tear,8,29);
-
- /* restore all the stuff on the hidden page */
-
- draw_screen(3);
-
- /* wait for a keystroke, restore the visual page, and return */
-
- fg_mousevis(ON);
- wait_for_keystroke();
-
- fg_mousevis(OFF);
- fg_restore(0,xlimit,menu_bottom,ylimit);
-
- fg_mousevis(ON);
- redraw = TRUE;
-
- return(OK);
- }
-
- /**********************************************************************\
- * *
- * do_scaling -- illustrate bitmap scaling *
- * *
- * The bird bitmap is stored as a 20x20 16-color mode-specific bitmap, *
- * which means its size in pixels is 40x20. *
- * *
- \**********************************************************************/
-
- char bird_unpacked[800]; /* unpacked bird bitmap (40x20) */
- char bird_scaled[3200]; /* scaled bird bitmap (80x40 max) */
- char bird_packed[1600]; /* packed and scaled bird bitmap (40x40 max) */
-
- do_scaling()
- {
- register int width, height;
- int x;
- char string[6];
-
- /* convert the 20x20 mode specific bitmap to a 40x20 unpacked bitmap */
-
- fg_unpack(bird1,bird_unpacked,20*20);
-
- /* the bird bitmap uses colors 5 and 15, change color 5 to black */
-
- fg_palette(5,0);
-
- /* display the original 40x20 bird bitmap */
-
- x = 60;
- fg_move(x,250);
- fg_mousevis(OFF);
- fg_drwimage(bird1,20,20);
- fg_setcolor(12);
- center_pstring("40x20",x,x+40,270);
-
- /* scale and display the 40x20 bird bitmap in increasingly larger sizes */
-
- for (width = 50; width <= 80; width+=10)
- {
- x += 100;
- fg_move(x,250);
- height = width / 2;
- fg_scale(bird_unpacked,bird_scaled,40,20,width,height);
- fg_pack(bird_scaled,bird_packed,width,height);
- fg_drwimage(bird_packed,width/2,height);
- sprintf(string,"%2dx%2d",width,height);
- center_pstring(string,x,x+width,270);
- }
-
- /* wait for a keystroke */
-
- fg_mousevis(ON);
- wait_for_keystroke();
- fg_mousevis(OFF);
-
- /* restore the screen and return */
-
- fg_restore(0,xlimit,menu_bottom,ylimit);
- fg_palettes(default_colors);
- redraw = TRUE;
- fg_mousevis(ON);
- return(OK);
- }
-
- /**********************************************************************\
- * *
- * do_scroll -- do a circular scroll of part of the screen *
- * *
- \**********************************************************************/
-
- do_scroll()
- {
- register int i;
- int y1,y2;
-
- y1 = 4;
- y2 = ylimit - y1;
-
- fg_mousevis(OFF);
-
- /* save the area under the scroll */
-
- fg_transfer(280,439,y1,y2,0,y2,hidden,hidden);
-
- /* do a nice circular scroll */
-
- for (i = y1; i <= y2; i+=2)
- fg_scroll(280,439,y1,y2,-2,0);
-
- /* fix the area under the scroll */
-
- fg_transfer(0,159,y1,y2,280,y2,hidden,hidden);
- fg_save(0,159,y1,y2);
-
- fg_mousevis(ON);
- return(OK);
- }
-
- /**********************************************************************\
- * *
- * do_split -- demo the split screen effect *
- * *
- \**********************************************************************/
-
- do_split()
- {
- register int y;
- int lower, upper;
-
- if (!exists("MOUNTAIN.PCX"))
- abort_program("File missing: MOUNTAIN.PCX.\n");
-
- /* the lower area will be page 0, the upper area page 1 */
-
- lower = 0;
- upper = 1;
-
- /* display the MOUNTAIN.PCX file on the hidden page (page 1) */
-
- fg_mousevis(OFF);
- fg_setpage(hidden);
- fg_showpcx("MOUNTAIN.PCX",0);
-
- /* activate a split screen environment with 100 lines at bottom */
-
- fg_split(ylimit-99);
- fg_setvpage(upper);
-
- /* pan the MOUNTAIN.PCX image (in the upper area) up */
-
- for (y = 0; y < 100; y++)
- fg_pan(0,y);
- fg_waitfor(4);
-
- /* now pan it back to its original position */
-
- for (y = 99; y >= 0; y--)
- fg_pan(0,y);
-
- /* wait for a keystroke */
-
- fg_mouselim(0,xlimit,0,ylimit-100);
- fg_mousevis(ON);
- wait_for_keystroke();
- fg_mouselim(0,xlimit,0,ylimit);
- fg_mousevis(OFF);
-
- /* disable the split screen environment */
-
- fg_setvpage(lower);
- fg_split(ylimit+1);
-
- /* restore the original menu screen */
-
- fg_palettes(default_colors);
- draw_screen(3);
- redraw = TRUE;
- return(OK);
- }
-
- /**********************************************************************\
- * *
- * do_transfer -- demo the transfer function *
- * *
- \**********************************************************************/
-
- do_transfer()
- {
- register int i;
- int x,y;
- int ymin,ymax;
-
- static char *string[] = {
- "Transfer",
- "Use Fastgraph's image transfer routines",
- "to copy rectangular areas, either on the",
- "same video page or different video pages."
- };
-
- /* clear work area of visual page and display the info window */
-
- fg_mousevis(OFF);
- fg_restore(0,xlimit,menu_bottom,ylimit);
- info_window(24,419,60,string,4);
-
- /* save the info window to the hidden page */
-
- ymin = 60;
- ymax = ymin + 5 * (PTSIZE+1) + 2;
- fg_save(24,419,ymin,ymax);
-
- /* transfer a 6 copies of the info window from hidden page to visual */
-
- x = 56;
- y = ymax+PTSIZE+1;
- for (i = 0; i < 6; i++)
- {
- fg_transfer(24,419,ymin,ymax,x,y,hidden,visual);
- x += 32;
- y += PTSIZE;
- fg_waitfor(2);
- }
-
- /* wait for a keystroke */
-
- fg_mousevis(ON);
- wait_for_keystroke();
-
- fg_mousevis(OFF);
-
- /* clear the area where the info window was on the hidden page */
-
- y = 5 * (PTSIZE+1) + 2;
-
- fg_transfer(24,419,ymax+1,ymax+y+1,24,ymax,hidden,hidden);
-
- /* restore the screen and return */
-
- fg_restore(0,xlimit,menu_bottom,ylimit);
- redraw = TRUE;
-
- fg_mousevis(ON);
- return(OK);
- }